#include <iostream>
#include <ctime>
#include <string>
using namespace std;

string sayHello(time_t now, string user) {
	tm* ltm = localtime(&now);
	int hour = ltm->tm_hour;
	string word;
	if (hour > 6 && hour <= 12) {
		word = "Good morning! ";
	}
	else if (hour > 12 && hour <= 19) {
		word = "Good afternoon! ";
	}
	else {
		word = "Good night! ";
	}
	return "Hi, " + user + ". " + word;
}

int main() {
	time_t now = time(0);
	string user = "John";
	cout << sayHello(now, user) << endl;

	tm* morning = localtime(&now);
	morning->tm_hour = 7;
	time_t am = mktime(morning);
	cout << sayHello(am, user) << endl;

	tm* afternoon = localtime(&now);
	afternoon->tm_hour = 13;
	time_t pm = mktime(afternoon);
	cout << sayHello(pm, user) << endl;

	tm* night = localtime(&now);
	night->tm_hour = 20;
	time_t nt = mktime(night);
	cout << sayHello(nt, user) << endl;

	return 0;
}